package edu.sctu.zcy.month201505.day20150515;

import edu.sctu.zcy.month201505.day20150514.Course;
import edu.sctu.zcy.month201505.day20150514.Student;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by user24 on 2015/5/15.
 */
public class SetTest {
    public List<Course> courseToSelect;
    public SetTest(){
        courseToSelect = new ArrayList<Course>();
    }
    public void textAdd(){

        Course cr1 = new Course("1","数据结构");
        courseToSelect.add(cr1);
        Course temp = (Course) courseToSelect.get(0);
        System.out.println("添加了一门课程："+temp.id+":"+temp.name);

        Course cr2 = new Course("2","高等数学");
        courseToSelect.add(0,cr2);
        Course temp1 = (Course) courseToSelect.get(0);
        System.out.println("添加了一门课程："+temp1.id+":"+temp1.name);

        Course[] courses = {new Course("3","C语言"),new Course("4","大学英语")};
        courseToSelect.addAll(Arrays.asList(courses));
        Course temp2 = (Course) courseToSelect.get(2);
        Course temp3 = (Course) courseToSelect.get(3);
        System.out.println("添加了两门课程："+temp2.id+"："+temp2.name);
        System.out.println(temp3.id+"："+temp3.name);

    }

    public void textForEach() {
        System.out.println("有如下课程2：");
        for (Object objects : courseToSelect) {

            Course course = (Course) objects;

            System.out.println(course.id + course.name);
        }
    }
    public static void main(String[] args) {

        SetTest st = new SetTest();
        st.textAdd();
        st.textForEach();

        Student student = new Student(1+"","姓名");
        System.out.println("欢迎学生"+student.name+"选课");

        Scanner scanner = new Scanner(System.in);

        for (int i = 0; i < 3; i++) {
            System.out.println("请输入课程id:");
            String courseid = scanner.next();

            for(Course cr:st.courseToSelect){
                if(cr.id.equals(courseid)){

                    student.Course.add(cr);

                }
            }
        }
        st.test(student);


    }
    public void test(Student student){
        for(Course course:student.Course){
            System.out.println("选择了课程："+course.id+"\n"+course.name);


        }
    }
}
